package com.system.elastic.controller;


import com.system.elastic.domain.Goods;
import com.system.elastic.domain.Result;
import com.system.elastic.domain.StatusCode;
import com.system.elastic.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/good")
public class GoodController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping(value = "/count" )
    public Integer count(){
        return goodsService.selectCount();
    }

    @GetMapping(value = "/list/{page}/{size}" )
    List list(@PathVariable(value ="page") Integer page, @PathVariable(value = "size")Integer size){
        return goodsService.queryList(page,size);
    }

    @PutMapping(value="/{id}")
    public Result update(@RequestBody Goods goods, @PathVariable String id){
        //设置主键值
        goods.setId(Long.valueOf(id));
        //调用SkuService实现修改Sku
        goodsService.saveOrUpdate(goods);
        return new Result(true, StatusCode.OK,"修改成功");
    }

}
